/*
 * @lc app=leetcode.cn id=1572 lang=javascript
 *
 * [1572] 矩阵对角线元素的和
 */

// @lc code=start
/**
 * @param {number[][]} mat
 * @return {number}
 */
var diagonalSum = function (mat) {
  const len = mat.length;
  let sum = 0;
  for (let i = 0; i < len; i++) {
    sum += mat[i][i];
    sum += mat[i][len - i - 1];
  }
  if (len % 2 === 1) {
    sum -= mat[(len - 1) / 2][(len - 1) / 2];
  }
  return sum;
};
// @lc code=end

